﻿#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <string>
using namespace std;

//1.==等于运算符；
class PersonEqual
{
public:
	PersonEqual(string name, int age)
	{
		this->m_Name = name;
		this->m_Age = age;
	}
	bool operator==(PersonEqual& p)
	{
		if (this->m_Name == p.m_Name && this->m_Age == p.m_Age)
		{
			return true;
		}
		return false;
	}
	bool operator!=(PersonEqual& p)
	{
		/*if (this->m_Name != p.m_Name || this->m_Age != p.m_Age)
		{
			return true;
		}
		return false;*/

		if (this->m_Name == p.m_Name && this->m_Age == p.m_Age)
		{
			return false;
		}
		return true;
	}
public:
	string m_Name;
	int m_Age;
};
void testRelationalOperator()
{
	PersonEqual p1("小明", 10);
	PersonEqual p2("小强", 15);

	int a = 20;
	int b = 20;
	if (a == b)
	{
		cout << "a,b相等！" << endl;//a,b相等！
	}

	if (p1 == p2)
	{
		cout << "p1 和 p2相等！" << endl;
	}
	else
	{
		cout << "p1 和 p2不相等！" << endl;//p1 和 p2不相等！
	}

	PersonEqual p3("小强", 15);
	if (p3 == p2)
	{
		cout << "p3 和 p2相等！" << endl;//p3 和 p2相等！
	}
	else
	{
		cout << "p3 和 p2不相等！" << endl;
	}

	if (p1 != p2)
	{
		cout << "p1 和 p2不相等！" << endl;//p1 和 p2不相等！
	}
	else
	{
		cout << "p1 和 p2相等！" << endl;
	}
}

//main282：关系运算符重载
int main282()
{
	testRelationalOperator();

	system("pause");
	return EXIT_SUCCESS;
}